<?php

namespace App\Models;

use Carbon\Carbon;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;

/**
 * App\BLog
 *
 * @property int $id
 * @property string $title
 * @property string $content
 * @property bool $recommend
 * @property bool $hot
 * @property string $published_at
 * @property \Carbon\Carbon $created_at
 * @property \Carbon\Carbon $updated_at
 * @method static \Illuminate\Database\Query\Builder|\App\Blog whereId($value)
 * @method static \Illuminate\Database\Query\Builder|\App\Blog whereTitle($value)
 * @method static \Illuminate\Database\Query\Builder|\App\Blog whereContent($value)
 * @method static \Illuminate\Database\Query\Builder|\App\Blog whereRecommend($value)
 * @method static \Illuminate\Database\Query\Builder|\App\Blog whereHot($value)
 * @method static \Illuminate\Database\Query\Builder|\App\Blog wherePublishedAt($value)
 * @method static \Illuminate\Database\Query\Builder|\App\Blog whereCreatedAt($value)
 * @method static \Illuminate\Database\Query\Builder|\App\Blog whereUpdatedAt($value)
 * @mixin \Eloquent
 */
class Blog extends Model
{

    protected $fillable = ['title', 'content', 'recommend', 'hot', 'published_at'];

    protected $dates=['published_at'];


    public function setPublishedAttribute($date)
    {
        $this->published_at = Carbon::createFromFormat('Y-m-d', $date);
    }

    /**
     * @param $query Builder
     */
    public function scopePublished($query)
    {
        $query->where('publish_at', '<=', Carbon::now());
    }
}
